from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from changliang import LUJING
import time


wd = webdriver.Chrome(service=Service(LUJING))
wd.implicitly_wait(2)
wd.get('https://www.byhy.net/cdn2/files/selenium/sample2.html')
time.sleep(1)

ele = wd.find_element(By.CLASS_NAME,'baiyueheiyu')
print(ele.get_attribute('innerHTML'))
print(ele.get_attribute('outerHTML'))
print(ele.get_attribute('innerTexT'))
print(ele.text)


wd.switch_to.frame('innerFrame')
print(wd.find_element(By.CLASS_NAME,'plant').text)

try:
    wd.find_element(By.ID,'outerbutton').click
except Exception:
    print('有问题')

wd.switch_to.default_content()
wd.find_element(By.ID,'outerbutton').click()
time.sleep(1)


wd.get('https://www.byhy.net/cdn2/files/selenium/sample3.html')
wd.find_element(By.TAG_NAME,'a').click()
main_html = wd.current_window_handle

time.sleep(2)

for i in wd.window_handles:
    wd.switch_to.window(i)
    if '必应' in wd.title:
        break

wd.find_element(By.ID,'sb_form_q').send_keys('纳斯达克')
wd.maximize_window()
wd.find_element(By.ID,'search_icon').click()
time.sleep(2)

wd.switch_to.window(main_html)
time.sleep(1)
wd.find_element(By.ID,'outerbutton').click()
time.sleep(2)
wd.quit()
